package com.medical.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.framework.aspectj.lang.annotation.Log;
import com.medical.framework.aspectj.lang.enums.BusinessType;
import com.medical.project.system.domain.DiseaseType;
import com.medical.project.system.service.IDiseaseTypeService;
import com.medical.framework.web.controller.BaseController;
import com.medical.framework.web.domain.AjaxResult;
import com.medical.common.utils.poi.ExcelUtil;
import com.medical.framework.web.page.TableDataInfo;

/**
 * 慢性病分类管理Controller
 * 
 * @author tale
 * @date 2020-05-24
 */
@RestController
@RequestMapping("/system/type")
public class DiseaseTypeController extends BaseController
{
    @Autowired
    private IDiseaseTypeService diseaseTypeService;

    /**
     * 查询慢性病分类管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(DiseaseType diseaseType)
    {
        startPage();
        List<DiseaseType> list = diseaseTypeService.selectDiseaseTypeList(diseaseType);
        return getDataTable(list);
    }

    /**
     * 导出慢性病分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "慢性病分类管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DiseaseType diseaseType)
    {
        List<DiseaseType> list = diseaseTypeService.selectDiseaseTypeList(diseaseType);
        ExcelUtil<DiseaseType> util = new ExcelUtil<DiseaseType>(DiseaseType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 获取慢性病分类管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(diseaseTypeService.selectDiseaseTypeById(id));
    }

    /**
     * 新增慢性病分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "慢性病分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DiseaseType diseaseType)
    {
        return toAjax(diseaseTypeService.insertDiseaseType(diseaseType));
    }

    /**
     * 修改慢性病分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "慢性病分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiseaseType diseaseType)
    {
        return toAjax(diseaseTypeService.updateDiseaseType(diseaseType));
    }

    /**
     * 删除慢性病分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "慢性病分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(diseaseTypeService.deleteDiseaseTypeByIds(ids));
    }
}
